package bussiness.core;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Bill;
import model.ForumUser;

import database.dao.BillDao;
import database.dao.UserDao;

/**
 * Servlet implementation class OrdersDetail
 */
public class OrdersDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrdersDetail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String username = (String)session.getAttribute("username");
		ForumUser user = UserDao.getUserByUserName(username);
		int userId = user.getUserId();
		if("1".equals(request.getParameter("type"))){
			Bill[] sbills = BillDao.getSellerBills(userId);
			BillDao.setBillsUsername(sbills);
			request.setAttribute("sbill", sbills);
		} else {
			Bill[] bbills = BillDao.getBuyerBills(userId);
			BillDao.setBillsUsername(bbills);
			request.setAttribute("bbill", bbills);
		}
		RequestDispatcher view = request.getRequestDispatcher("/WEB-INF/jsp/orderlist.jsp");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
